<template>
    <el-tabs :model-value="modelValue" type="card" class="tabs-bar" :class="isDark ? 'dark' : ''" @tab-remove="onRemove"
        @tab-click="onTabClick">
        <el-tab-pane v-for="tab in tabs" :key="tab.name" :label="tab.label || tab.name" :name="tab.name"
            :closable="tab.closable !== false" />
    </el-tabs>
</template>
<script setup>
import { defineEmits, defineProps } from 'vue'

defineProps({
    modelValue: String,
    tabs: Array,
    isDark: Boolean
})

const emit = defineEmits(['update:modelValue', 'remove', 'tab-click'])

function onRemove(name) {
    emit('remove', name)
}

function onTabClick(tab) {
    emit('tab-click', tab)
}
</script>
<style scoped>
.tabs-bar {
    margin-top: 0;
    margin-bottom: 0;
    background: transparent;
    border-bottom: none;
    padding-left: 0;
}

:deep(.el-tabs__header),
:deep(.el-tabs__nav-wrap),
:deep(.el-tabs__nav-wrap::after),
:deep(.el-tabs__content) {
    border-bottom: none !important;
    border-top: none !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

:deep(.el-tabs__nav) {
    background: #fff;
    border-radius: 8px 8px 0 0;
    min-height: 48px;
    border: none !important;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.04);
    padding: 0 12px;
    display: flex;
    align-items: center;
}

:deep(.el-tabs__item) {
    font-size: 15px;
    font-weight: 500;
    color: #222;
    padding: 0 22px;
    min-width: 80px;
    height: 48px;
    line-height: 48px;
    border: none;
    background: transparent;
    border-radius: 8px 8px 0 0;
    margin-right: 8px;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

:deep(.el-tabs__item.is-active) {
    background: #fff;
    color: var(--el-color-primary, #409EFF);
    border-bottom: 2px solid var(--el-color-primary, #409EFF);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 2;
}

:deep(.el-tabs__item:not(.is-active):hover) {
    background: #f5f7fa;
    color: var(--el-color-primary, #409EFF);
}

:deep(.el-tabs__item .el-icon-close) {
    font-size: 14px;
    margin-left: 4px;
}

/* 深色模式 */
.dark :deep(.el-tabs__nav) {
    background: #232324 !important;
    border: none !important;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.16) !important;
}

.dark :deep(.el-tabs__item) {
    color: #a8abb2 !important;
    background: transparent !important;
    border: none !important;
}

.dark :deep(.el-tabs__item.is-active) {
    background: #232324 !important;
    color: #409EFF !important;
    border-bottom: 2px solid #409EFF !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18) !important;
}

.dark :deep(.el-tabs__item:not(.is-active):hover) {
    background: #18181c !important;
    color: #409EFF !important;
}

.dark :deep(.el-tabs__item .el-icon-close) {
    color: #a8abb2 !important;
}

.dark :deep(.el-tabs__item .el-icon-close:hover) {
    color: #f56c6c !important;
}

:deep(.el-tabs__nav-wrap),
:deep(.el-tabs__nav-wrap::after),
:deep(.el-tabs__content),
:deep(.el-tabs__item),
:deep(.el-tabs__item:before),
:deep(.el-tabs__item:after),
:deep(.el-tabs__nav),
:deep(.el-tabs__nav:before),
:deep(.el-tabs__nav:after) {
    border: none !important;
    outline: none !important;
}
</style>